Results 1 to 15 of 15

Thread: How Do I get the “friendly” name of serial port

  1. #1
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default How Do I get the “friendly” name of serial port

    Hi ,
    I am using QT4 in windows to develop an GUI application which is used to communicate with a Hardware Electronic unit through USB. I am having a UDB serial cable connected between system and Electronic unit .It shows in Device Manager as "MOXA USB Serial Port (COM2)".
    In program I can able to get the active ports by checking whether it is open or not.But I want to be able to get the "friendly" .It means COM2 is not a friendly name. I want something that says "COM2 - USB connector" or something like that. It is nasty and hacky, but many times end users have no idea what COM port they need to open in my program unless there is a useful name - more useful than "COMn."
    I want to know is it possible to do using QT or I have to use any windows Native API. If I have to use windows Native API what i have to do ,I mean which API I have to use and how it should include in my QT program,I means whether I have to include any windows libraries or any header files and which one I have to include.
    SO please suggest me to solve this problem.

    With regards,
    Sudheer.

  2. #2
    Join Date
    Sep 2008
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How Do I get the “friendly” name of serial port

    Hi sudheer168!

    I wonder how do you access the com port. Are you using some native win32 api functions or the QextSerialPort library? In QextSerialPort the ports can be enumerated and some useful information can be acquired, but I'm afraid it'll only return "COMx" for friendly name, I haven't tried it yet with non native serial ports, so I'm not sure. It's worth to try.
    If that doesn't help you, and if platform dependency doesn't bothers you, consider using WMI (Windows Management Instrumentation). A huge amount of system information can be extracted from it, including hardware related stuff like com ports. This example should be enough to get started. The caption for the port (the exact same text what you can see in device manager), can be acquired using this query text "SELECT Caption FROM Win32_SerialPort".
    Last edited by gsmiko; 22nd June 2009 at 20:02.

  3. #3
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How Do I get the “friendly” name of serial port

    Hi thanks for y our kind reply.
    Actually I am using QextSerialPort library that is why I am unable to get the friendly name of the com port. You suggest me to use WMI ,there is no problem to use.But one thing I want to know is how can I use the WMI in my Qt application.I mean whether I have to integrate any library or I have have to include any header file to use WMI.
    So please suggest me to solve this problem.

    With regards,
    Sudheer.

  4. #4
    Join Date
    Sep 2008
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How Do I get the “friendly” name of serial port

    This example covers all the things you need to know. You have to include comdef.h, and Wbemidl.h, and you have to link with wbemuuid.lib. All of these can be found in the Windows SDK, no 3rd party stuff is required.

  5. #5
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How Do I get the “friendly” name of serial port

    Hi gsmiko, thanks for your kind reply.
    I gone through the example code which you have suggested me.I included the comdef.h, and Wbemidl.h in my QT application class and linked with wbemuuid.lib.But in if I used the API ,while compiling it is showing errors as ...
    Qt Code:
    1. error C3861: 'CoInitializeEx': identifier not found, even with argument-dependent lookup
    2. error C2065: 'COINIT_MULTITHREADED' : undeclared identifier
    To copy to clipboard, switch view to plain text mode 

    The errors I posted above are few that I occour.So how can I be out of these type of errors.
    So please help me to solve this problem.

    With Regards,
    Sudheer.

  6. #6
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How Do I get the “friendly” name of serial port

    2 sudheer168,


    Try to use my library QSerialDevice. See in attach

    in library see method : QStringList serialDevicesAvailable()
    Attached Files Attached Files

  7. #7
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How Do I get the “friendly” name of serial port

    Hi kuzulis,
    thanks for your support.I linked the QSerialDevice library to my applications .As you told I used QStringList serialDevicesAvailable() to acces serialport devices that are available . The List shows the COM details ie names as COM1,COM2 .But I want hte friendly name of the com port ,I mean if I insert any USB device in the USB port system ,the device manager shows the friendly name along with COMn.
    So using this library how can get the friendly name of the com port ,if not possible using this library tell me the alternative to do this.
    So please help me to solve this problem.


    With regards,
    Sudheer

  8. #8
    Join Date
    Sep 2008
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How Do I get the “friendly” name of serial port

    Quote Originally Posted by sudheer168 View Post
    Hi gsmiko, thanks for your kind reply.
    I gone through the example code which you have suggested me.I included the comdef.h, and Wbemidl.h in my QT application class and linked with wbemuuid.lib.But in if I used the API ,while compiling it is showing errors as ...
    Qt Code:
    1. error C3861: 'CoInitializeEx': identifier not found, even with argument-dependent lookup
    2. error C2065: 'COINIT_MULTITHREADED' : undeclared identifier
    To copy to clipboard, switch view to plain text mode 

    The errors I posted above are few that I occour.So how can I be out of these type of errors.
    So please help me to solve this problem.

    With Regards,
    Sudheer.
    The first step of course would be to build the example from msdn as is, to make sure everything is configured correctly. I think you're missing some includepaths, please post the complete build log. By the way, which compiler are you using, VC or MinGW?

  9. #9
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How Do I get the “friendly” name of serial port

    2 sudheer168,

    In Windows XP, etc. This library uses a method serialDevicesAvailable.

    This method reads the Windows registry on the way:
    "HKEY_LOCAL_MACHINE \ \ Hardware \ \ Devicemap \ \ Serialcomm"

    You connect the converter USB <-> RS232 and look in the registry using regedit.exe - or do not appear in the registry entry ...

    If the entry appears, then I think the method serialDevicesAvailable - detects the new device. You need to check :-)

  10. #10
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How Do I get the “friendly” name of serial port

    oops ... Once again, I read your post - and I think that in this case, no!

    because method serialDevicesAvailable () can get names:
    or COM1 ... COMn
    or / Device/Serial0 ... /Device/Serialn

    While it may be the friendly name is also stored somewhere in the registry .. But I do not know where

    Perhaps you need to use WMI - but it requires extra header files and libraries!

    Question: What do you friendly name?

  11. #11
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How Do I get the “friendly” name of serial port

    Hi gsmiko, thanq for your reply.I am using MSVS .Net 2003.


    2 kuzulis,
    me to gone through it ,I got values as COMn and names as / Device/Serial0 ... /Device/Serialn. I want to know friendly name because ,I have to know to which com port my
    USB <-> RS 232 was connected and by knowing the COMn dynamically I can able to communicate using QExtserialport library . And one more thing does this Qserialdevice is platform independent.
    So suggest me to solve this problem.

    With regards,
    sudheer.

  12. #12
    Join Date
    Sep 2008
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How Do I get the “friendly” name of serial port

    Hmm, very interesting.
    The easiest solution would be to send you a sample project, but I'm using msvc2008, so thats out of the question. I would be nice to see the full build log, and the parts of the code where you tried to integrate the sample code from msdn.

  13. #13
    Join Date
    Dec 2009
    Location
    New Zealand
    Posts
    54
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How Do I get the “friendly” name of serial port

    Hi sudheer168,

    Just wondering, did you find a solution to finding the friendly names of the serial ports? I have a similar problem.

  14. #14
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How Do I get the “friendly” name of serial port

    If you use something like:

    Qt Code:
    1. hDevInfo = SetupDiGetClassDevs (&GUID_CLASS_COMPORT, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
    2.  
    3. for (ii = 0; bOk; ii++)
    4. bOk = SetupDiEnumDeviceInterfaces (hDevInfo, NULL, &GUID_CLASS_COMPORT, ii, &ifcData);
    5. if (bOK) {
    6. bOk = SetupDiGetDeviceInterfaceDetail (hDevInfo, &ifcData, pDetData, dwDetDataSize, NULL, &devdata);
    To copy to clipboard, switch view to plain text mode 

    (obviously you'll need some variables with the above too, and some more error checking. It's just a rough idea)
    then you can get the friendly name like so:

    Qt Code:
    1. bSuccess = SetupDiGetDeviceRegistryProperty (hDevInfo, &devdata, SPDRP_FRIENDLYNAME, NULL,
    2. (PBYTE)fname, sizeof (fname), NULL);
    To copy to clipboard, switch view to plain text mode 

    You can also gets lots of other stuff, see http://msdn.microsoft.com/en-us/library/ms792967.aspx

    (Obviously this is Windows specific)

  15. #15
    Join Date
    Dec 2009
    Location
    New Zealand
    Posts
    54
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How Do I get the “friendly” name of serial port

    The following answer is based on the "enumerator" example from the "qextserialport-1.2win-alpha" folder:

    Qt Code:
    1. void Loader::getCOMPortName()
    2. {
    3.  
    4. QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
    5. qDebug() << ("List of ports:\n");
    6. qDebug() << ports.size();
    7. for (int i = 0; i < ports.size(); i++)
    8. {
    9. qDebug() << ("port name: %s\n", ports.at(i).portName.toLocal8Bit().constData());
    10. qDebug() << ("friendly name: %s\n", ports.at(i).friendName.toLocal8Bit().constData());
    11. qDebug() << ("physical name: %s\n", ports.at(i).physName.toLocal8Bit().constData());
    12. qDebug() << ("enumerator name: %s\n", ports.at(i).enumName.toLocal8Bit().constData());
    13. qDebug() << ("===================================\n\n");
    14. }
    15. //return EXIT_SUCCESS;
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 


    The attachment shows what I get as debug output from my system.
    Attached Images Attached Images

Similar Threads

  1. serial port same local machine
    By adamatic in forum Qt Programming
    Replies: 7
    Last Post: 3rd February 2009, 07:29
  2. serial port programming
    By sujatashooter in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2008, 15:51
  3. accessing serial port without CONFIG += console
    By bnilsson in forum Qt Programming
    Replies: 2
    Last Post: 21st July 2008, 21:47
  4. First attempt to display serial port data on GUI
    By ShaChris23 in forum Newbie
    Replies: 12
    Last Post: 4th May 2007, 09:14
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.